package com.idc.common.mvc.vo;

import com.idc.common.constant.ErrorCode;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * The type Response vo.
 *
 * @param <T> the type parameter
 * @author
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResponseVo<T> {
    private Integer code;
    private String msg;
	private Boolean status;
    private T data;

    /**
     * Success response vo.
     *
     * @param <T>  the type parameter
     * @param data the data
     * @return the response vo
     */
    public static <T> ResponseVo<T> success(T data) {
		return new ResponseVo<T>(200, "成功", true, data);
    }
    
    public static <T> ResponseVo<T> success() {
		return new ResponseVo<T>(200, "成功", true, null);
    }

    /**
     * Fail response vo.
     *
     * @param <T>  the type parameter
     * @param code the code
     * @param msg  the msg
     * @return the response vo
     */
    public static <T> ResponseVo<T> fail(Integer code, String msg) {
		return new ResponseVo<T>(code, msg, false, null);
    }

	public static <T> ResponseVo<T> fail(ErrorCode errorCode) {
		return new ResponseVo<T>(errorCode.getCode(), errorCode.getMessage(), false, null);
	}

    public static <T> ResponseVo<T> failMsg(Integer code, String msg,T data) {
		return new ResponseVo<T>(code, msg, false, data);
    }

	@Override
	public String toString() {
		return "ResponseVo [code=" + code + ", msg=" + msg + ", status=" + status + ", data=" + data + "]";
	}

}
